
package rpg.cenario;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.*;

/**
 *
 * @author Gean
 * @version 1.0
 * @since 25/02/13
 */
public class FrameMapa extends JFrame{
    
    // Componentes de interface sendo declarados
    private JPanel panel1;
    private JLabel label1;
    private JButton button1;
    private JButton button2;
    private JButton button3;
    private JButton button4;
    private JButton button5;
    private JButton button6;
    private JButton button7;
    private JButton button8;
    private JButton button9;
    private JButton temp;
    
    /*
     * Método construtor, que inicializa todos os componentes, define valores
     * a eles, e lhes posiciona em um JFrame
     */
    public FrameMapa(){
        super("teste");
        
        Container c = this.getContentPane();
        TrataEventosBotoes teb = new TrataEventosBotoes();
        
        // JPanel
        panel1 = new JPanel();
        panel1.setLayout(new FlowLayout());
        panel1.setPreferredSize(new Dimension(800, 500));
        
        // JLabel
        label1 = new JLabel(null, new ImageIcon(getClass().getResource("/img/mapa.jpg")), SwingConstants.CENTER);
        
        //JButtons
        button1 = new JButton(new ImageIcon(getClass().getResource("/img/pontovermelho1.png")));
        button1.setBorderPainted(false);
        button1.setContentAreaFilled(false);
        button1.setBounds(36, 60, 30, 30);
        button1.addActionListener(teb);
        
        button2 = new JButton(new ImageIcon(getClass().getResource("/img/pontovermelho2.png")));
        button2.setBorderPainted(false);
        button2.setContentAreaFilled(false);
        button2.setBounds(115, 118, 30, 30);
        button2.addActionListener(teb);
        
        button3 = new JButton(new ImageIcon(getClass().getResource("/img/pontovermelho3.png")));
        button3.setBorderPainted(false);
        button3.setContentAreaFilled(false);
        button3.setBounds(36, 150, 30, 30);
        
        button4 = new JButton(new ImageIcon(getClass().getResource("/img/pontovermelho4.png")));
        button4.setBorderPainted(false);
        button4.setContentAreaFilled(false);
        button4.setBounds(125, 240, 30, 30);
        
        button5 = new JButton(new ImageIcon(getClass().getResource("/img/pontovermelho5.png")));
        button5.setBorderPainted(false);
        button5.setContentAreaFilled(false);
        button5.setBounds(200, 178, 30, 30);
        
        button6 = new JButton(new ImageIcon(getClass().getResource("/img/pontovermelho6.png")));
        button6.setBorderPainted(false);
        button6.setContentAreaFilled(false);
        button6.setBounds(285, 210, 30, 30);
        
        button7 = new JButton(new ImageIcon(getClass().getResource("/img/pontovermelho7.png")));
        button7.setBorderPainted(false);
        button7.setContentAreaFilled(false);
        button7.setBounds(340, 125, 30, 30);
        
        button8 = new JButton(new ImageIcon(getClass().getResource("/img/pontovermelho8.png")));
        button8.setBorderPainted(false);
        button8.setContentAreaFilled(false);
        button8.setBounds(372, 248, 30, 30);
        
        button9 = new JButton(new ImageIcon(getClass().getResource("/img/pontovermelho9.png")));
        button9.setBorderPainted(false);
        button9.setContentAreaFilled(false);
        button9.setBounds(470, 95, 30, 30);
        
        //adds 
        label1.add(button1);
        label1.add(button2);
        label1.add(button3);
        label1.add(button4);
        label1.add(button5);
        label1.add(button6);
        label1.add(button7);
        label1.add(button8);
        label1.add(button9);
        panel1.add(label1);
        c.add(panel1);
        
    }
   /**
    * Classe interna privada criada com a finalidade de tratar
    * eventos. Ela implementa os eventos do tipo "ActionListener"
    */
    private class TrataEventosBotoes implements ActionListener{

        /*
         * Método que trata os eventos do tipo ActionListener
         * 
         * @param e, do tipo ActionEvent
         */
        public void actionPerformed(ActionEvent e) {
           if(e.getSource() == button1){
               label1.setIcon(new ImageIcon(getClass().getResource("/img/lugar1.png")));
               button1.setVisible(false);
               button2.setVisible(false);
               button3.setVisible(false);
               button4.setVisible(false);
               button5.setVisible(false);
               button6.setVisible(false);
               button7.setVisible(false);
               button8.setVisible(false);
               button9.setVisible(false);
               temp = new JButton(new ImageIcon(getClass().getResource("/img/voltar.png")));
               temp.setBorderPainted(false);
               temp.setContentAreaFilled(false);
               temp.setVisible(true);
               temp.setBounds(600, 300, 48, 48);
               temp.addActionListener(this);
               label1.add(temp);
               
           } else if(e.getSource() == button2){
               label1.setIcon(new ImageIcon(getClass().getResource("/img/batalha.png")));
               button1.setVisible(false);
               button2.setVisible(false);
               button3.setVisible(false);
               button4.setVisible(false);
               button5.setVisible(false);
               button6.setVisible(false);
               button7.setVisible(false);
               button8.setVisible(false);
               button9.setVisible(false);
               temp = new JButton(new ImageIcon(getClass().getResource("/img/voltar.png")));
               temp.setBorderPainted(false);
               temp.setContentAreaFilled(false);
               temp.setVisible(true);
               temp.setBounds(600, 300, 48, 48);
               temp.addActionListener(this);
               label1.add(temp);
           } else if(e.getSource() == temp){
               label1.setIcon(new ImageIcon(getClass().getResource("/img/mapa.jpg")));
               temp.setVisible(false);
               button1.setVisible(true);
               button2.setVisible(true);
               button3.setVisible(true);
               button4.setVisible(true);
               button5.setVisible(true);
               button6.setVisible(true);
               button7.setVisible(true);
               button8.setVisible(true);
               button9.setVisible(true);
           }
        
        }
        
    }
    
    /*
     * Método main, criado com a finalidade de testar a classe "FrameMapa" que 
     * cria uma interface gráfica
     * 
     * @param String[] args
     */
  
    public static void main(String[] args) {
        FrameMapa f = new FrameMapa();
        f.setSize(800, 500);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setLocationRelativeTo(null);
        f.setVisible(true);
        f.setResizable(false);
    }
    
}
    
    
    

